package by.sjc.grsu.dao.repositiory.impl;

import by.sjc.grsu.dao.base.AbstractHibernateDao;
import by.sjc.grsu.dao.repositiory.SubscriptionsDao;
import by.sjc.grsu.model.Subscription;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Transactional
public class SubscriptionsRepository extends AbstractHibernateDao<Subscription, Integer> implements SubscriptionsDao {

    @Override
    @SuppressWarnings("unchecked")
    public List<Subscription> findByAccountId(int accountId) {
        return getSession().createCriteria(Subscription.class)
                .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
                .add(Restrictions.eq("account.id", accountId))
                .list();
    }
}
